import { Component, OnInit } from '@angular/core';

import { Hero } from '../hero-detail/hero.model'
import { LoggerService } from '../services/loggerService'
import { HeroService } from '../services/heroService'

@Component({
  selector: 'hero-list',
  templateUrl: './hero-list.component.html',
  styleUrls: ['./hero-list.component.css']
})
export class HeroListComponent implements OnInit {

  heroes: Hero[];
  selectedHero: Hero;

  constructor(
    private loggerService: LoggerService,
    private heroService: HeroService
  ) { }

  ngOnInit() {
    this.heroes = this.heroService.getAllHeroes();
    this.loggerService.log('hero list ngOnInit');
  }

  selectHero(hero: Hero): void {
    if (!hero)
      return;

    this.selectedHero = hero;
  }

}
